#include <stdio.h>
#include <error.h>
#define LOG "log.txt"

//C语言的文件读写
int main()
{
    //FILE* fp = fopen(LOG,"w");
    FILE* fp = fopen(LOG,"r");
    if(fp == NULL)
    {
        perror("fail:");
    }
    
    //写
    //int cnt = 10;
    //while(cnt)
    //{
    //    fprintf(fp,"hello %d\n",cnt--);
    //}
    
    //const char* s = "hello ckf";
    //char buf[1024] = {0};
    //int cnt = 10;
    //while(cnt)
    //{
    //    //先写入缓冲区再写入文件
    //    snprintf(buf,sizeof(buf),"%s:%d\n",s,cnt--);
    //    fputs(buf,fp);
    //}
    
    //读
    char buf[1024] = {0};
    //fgets按行读取
    while(fgets(buf,sizeof(buf),fp))
    {
        printf("%s",buf);
    }
    

    fclose(fp);
    return 0;
}
